package com.bootdo.loa;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import com.bootdo.common.config.Constant;
import com.bootdo.common.controller.BaseController;
import com.bootdo.common.service.DictService;
import com.bootdo.common.utils.ShiroUtils;
import com.bootdo.system.domain.SuyongDO;
import com.bootdo.system.domain.UserDO;
import com.bootdo.system.service.SuyongService;
import com.bootdo.system.service.UserOldService;
import com.bootdo.system.service.UserRoleService;
import com.bootdo.system.service.UserService;
import com.mysql.jdbc.StringUtils;

@Controller
public class AuthorizationController extends BaseController {
	@Autowired
	DictService dicService;

	@Autowired
	SuyongService suyongService;

	@Autowired
	UserService userService;

	@Autowired
	UserOldService useroldService;
	
	@Autowired
	UserRoleService userRoleService;

	@GetMapping("/authorization")
	public String getauth(Model model, HttpServletRequest request) {
		String str;
		UserDO user = getUser();
		int roleId = userRoleService.getByUserId(getUserId());
		if (roleId == 3) {
			model.addAttribute("role", 0);
		} else {
				
			str = suyongService.get(user.getId()).getAuthNo();

			
			model.addAttribute("role", 1);
			Authorization auth = new Authorization();
			auth.setCompany(user.getCompanyName());
			auth.setAuthNo(str);
			auth.setStartYear(str.substring(0, 4));
			auth.setStartMonth(str.substring(4, 6));
			auth.setStartDay(str.substring(6, 8));
			auth.setEndYear(
					(Integer.parseInt(str.substring(0, 4)) + Integer.parseInt(dicService.getValue(Constant.AUTH_YEAR)))
							+ "");
			auth.setEndMonth(str.substring(4, 6));
			auth.setEndDay(str.substring(6, 8));
			model.addAttribute("auth", auth);
		}

		return "authorization";
	}

}
